<template>
	<div>
		<el-dialog title="肝损害剂量" :visible.sync="dialogVisibleXiangHu" width="60%" :before-close="handleClose">
			<el-card style="margin-top:10px">
				<el-button type="primary" class="gs_add fr" @click="add">新增</el-button>
				<Graytable :tHead="tHead" :tData="tData"  @operateClick="operateClick"></Graytable>
				<pagination
					:total="query.total"
					:page.sync="query.page"
					:limit.sync="query.limit"
					@pagination="getList"/>
			</el-card>
			<span slot="footer" class="dialog-footer">
				<el-button @click="dialogVisibleXiangHu = false">关 闭</el-button>
			</span>
		</el-dialog>
		<SelectDialog ref="selectDialog" ctype="肝损害剂量" cintype="给药途径" :dataObj="nowData" :checkId="checkId" @selectFun="selectFun"></SelectDialog>
		<SelectDialog ref="selectDialogjb" ctype="肝损害剂量" cintype="疾病状态" :dataObj="nowData" :checkId="checkId1" @selectFun="selectFun"></SelectDialog>
		<gshSetCard ref="gshSetCard" @selectPop="selectPop" :gyData="gyData" :jbData="jbData" :nowData="nowData" @changeFun="resetTData"></gshSetCard>
	</div>
</template>

<script>
	import SelectDialog from "./selectDialog";
	import gshSetCard from "./gshSetCard";
	export default {
		components: {
			SelectDialog,
			gshSetCard
		},
		props:{
			dataObj:{
				required:true
			}
		},
		data () {
			return {
				query: {
				  total: 0,
				  page: 1,
				  limit: 10
				},
				dialogVisibleXiangHu:false,
				tHead:[
					{
						label:"操作",
						operate:["删除","修改"],
						align:"center",
						width:"100px"
					},
					{
						prop:"warning",
						label:"警示"
					},
					{
						prop:"intercept",
						label:"拦截"
					},
					{
						prop:"dosingUnit",
						label:"给药单位"
					},
					{
						prop:"dosingUnit_code",
						label:"给药途径编码"
					},
					{
						prop:"dosingUnit_name",
						label:"给药途径名称"
					},
					{
						prop:"degreeVal",
						label:"肝损害程度"
					},
					{
						prop:"age",
						label:"年龄段"
					},
					{
						prop:"diseaseStates",
						label:"疾病状态"
					},
					{
						prop:"calculationVal",
						label:"计算方式"
					},
					{
						prop:"doseRange",
						label:"每次推荐剂量范围"
					},
					{
						prop:"dailyDose",
						label:"每日推荐剂量范围"
					},
					{
						prop:"dosingFrequency",
						label:"给药频次"
					},
					{
						prop:"operUser",
						label:"维护人"
					},
					{
						prop:"insTime",
						label:"维护日期"
					},
				],
				tData:[],
				checkId:"",
				checkId1:"",
				nowData:{},
				gyData:{id:"",name:""},
				jbData:{id:"",name:""},
			}
		},
		watch:{
			dataObj(val){
				this.nowData=val;
				this.resetTData(true);
			}
		},
		methods:{
			add () {
				this.$refs.gshSetCard.show();
			},
			selectPop (type,checkId,multi) {
				this.ctype=type;
				if(type == "给药途径"){
					this.checkId = checkId;
					this.$refs.selectDialog.show()
				}else{
					this.checkId1 = checkId;
					this.$refs.selectDialogjb.show()
				}
			},
			selectFun(id,name){
				if(this.ctype == "给药途径"){
					this.gyData = {
						id:id,
						name:name
					};
				}else{
					this.jbData = {
						id:id,
						name:name
					};
				}
			},
			clearFun(type){
				if(this.ctype == "给药途径"){
					this.gyData = {
						id:"",
						name:""
					};
				}else{
					this.jbData = {
						id:"",
						name:""
					};
				}
				this.checkId="";
				this.checkId1="";
			},
			async getList () {
				let res=await this.$custom.listliverDamageListFull({
					drugUniqueCode:this.nowData.drugUniqueCode,
					page:this.query.page,
					pageSize:this.query.limit
				})
				for(var i in res.rows){
					res.rows[i].warning == 1 ? res.rows[i].warning = "是" : res.rows[i].warning = "否";
					res.rows[i].intercept == 1 ? res.rows[i].intercept = "是" : res.rows[i].intercept = "否";
					if(res.rows[i].degree == 1){
						res.rows[i].degreeVal = "肝功能不全";
					}else if(res.rows[i].degree == 2){
						res.rows[i].degreeVal = "轻度肝损害";
					}else if(res.rows[i].degree == 3){
						res.rows[i].degreeVal = "中度肝损害";
					}else if(res.rows[i].degree == 4){
						res.rows[i].degreeVal = "重度肝损害";
					}
					if(res.rows[i].calculation == 1){
						res.rows[i].calculationVal = "常规";
					}else if(res.rows[i].calculation == 2){
						res.rows[i].calculationVal = "体重";
					}else if(res.rows[i].calculation == 3){
						res.rows[i].calculationVal = "体表";
					}
					
					res.rows[i].tjbfb = res.rows[i].recommendEachLow + "%至" + res.rows[i].recommendEachHigh + "%";
					res.rows[i].tjrml = res.rows[i].recommendRmLow + "ml至" + res.rows[i].recommendRmHigh + "ml";
					res.rows[i].xzbfb = res.rows[i].warnEachLow + "%至" + res.rows[i].warnEachHigh + "%";
					res.rows[i].xzrml = res.rows[i].warnRmLow + "ml至" + res.rows[i].warnRmHigh + "ml";
				}
				this.tData=res.rows;
				this.query.total=res.total;
			},
			show(){
				this.dialogVisibleXiangHu = true;
			},
			resetTData(flag){
				this.checkId="";
				this.checkName="";
				this.query={
					total:0,
					page:1,
					limit:10
				}
				this.tData=[];
				this.getList();
				if(!flag){
					this.$emit("changeFun")
				}
			},
			handleClose () {
				this.dialogVisibleXiangHu = false;
			},
			operateClick(item,row){
				this.$confirm('确定删除通用自定义?', '提示', {
					confirmButtonText: '确定删除',
					cancelButtonText: '取消',
					type: 'warning'
				}).then(() => {
					this.delFun(row);
				}).catch(() => {
				});
			},
			async delFun(row){
				let res=await this.$custom.listliverDamageDelete({
					drugUniqueCodeRz:row.drugUniqueCodeRz,
					id:row.id
				})
				this.$message({
				  message: res.msg,
				  type: res.code == 1?'success':'error',
				  duration:1500
				});
				this.resetTData();
			}
		}
	}
</script>

<style lang="scss" scoped>
	.gs_add{
		margin-bottom:20px;
	}
	.tip{
		color:red;
		line-height:20px;
	}
	.el-card {
		margin-left: 3px;
	}

	.SearchT {
		display: flex;
		justify-content: flex-end;
		height: 40px;
		align-items: center;
		background-color: #e6edf3;
		font-size: 14px;
	}

	.tableLable {
		flex: 1;
		text-align: left;
		margin-left: 15px;
		letter-spacing: 2px;
		font-size: 14px;
		color: #32a6f3;
		font-weight: bold;
	}

	/* .exportBtn {
  margin-right: 23px;
}
.BatchDeleBtn {
  margin-right: 15px;
} */
	.tableStyle {
		width: 100%;
		height: 100%;
	}

	.card-table {
		width: 100%;
		height: 75%;
	}

	.block {
		text-align: center;
		margin-top: 12px;
		margin-bottom: 12px;
	}

	.Btn {
		display: flex;
		flex: 1;
		flex-wrap: nowrap;
	}

	.dialogFirstRow>>>.el-input {
		width: 70px;
	}

	.el-form-item.s_selectbox>>>.el-form-item__content {
		width: 80%;
	}
	/* .demo-form-inline>>>.el-form-item {
		margin-bottom: 0px;
	} */
	.box{
		height:30px;
		line-height:30px;
		font-size:12px;
		border-bottom:1px solid #ccc;
		.label{
			width:100px;
			background:#28a4f4;
			padding-right:5px;
			color:#fff;
			text-align:right;
			float:left;
		}
		.value{
			padding-left:5px;
			color:#333;
			margin-left:100px;
		}
	}
</style>
